/**
 * curry柯里化ts实现
 * 1、()=>R 没有参数
 * 2、(p)=>R 一个参数
 * 3、(p)=>新的函数 多个参数
 */

type Curried<A extends unknown[], R> = A extends []
  ? () => R
  : A extends [infer ARG]
  ? (p: ARG) => R
  : A extends [infer ARG, ...infer REST]
  ? (p: ARG) => Curried<REST, R>
  : never;

declare function curry<A extends unknown[], R>(func: (...args: A) => R): Curried<A, R>;

function sum(a: number, b: number, c: number) {
  return a + b + c;
}

const curried = curry(sum);
const r = curried(1)(2)(3);
